Workflow script is normally used after submitting a to do task. To do task triggers the script to execute and complete the workflow.
info
Write the script in a template service for workflows calling.
Creating Object Service
Add 3 input parameters to represent data involved in workflows.
- data: JSON data from business form transmitted from the previous task.
{
"name": "Emma",
"sex": "F"
...
}
- auditData: Branch task information.
Parameter | Type | Description |
---|---|---|
name | string | Branch name |
reject | boolean | Whether to reject the branch task |
order | integer | Branch code. |
- flowData: Workflow information.
Parameter | Type | Description |
---|---|---|
processId | string | Process instance ID |
processName | string | Process name |
taskName | string | To do task name |
taskId | string | To do task ID |
userId | string | Executor ID of the to do task |
staffName | string | Executor name |
initiatorId | string | Process initiator ID |
initiatorName | string | Process initiator name |
createTime | string | Receive time of the to do task |
Writing Service Script
var formDataJson = JSON.parse(data); // JSON data of the form
var auditDataJson = JSON.parse(auditData);
var flowDataJson = JSON.parse(flowData);
var name = auditDataJson.name; //branch task name
var order = auditDataJson.order; //branch task name
var isReject = auditDataJson.reject; //whether to reject the branch task
var taskName = flowDataJson.taskName;//currently submitted task name
var startUser = flowDataJson.initiatorName;//process initiator name
var processId = flowDataJson.processId;//current process instance ID
var taskId = flowDataJson.taskId; //currently submitted task ID
//TODO specific business logic
.....
var result = {
"code": "200", // 200 represents success. Error returns codes other than 200 and 201
"message": "error message"
}
result;